package com.augurit.gzcgwsp.ljzyz.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dozer.DozerBeanMapper;

import com.augurit.common.util.lang.DateUtils;
import com.augurit.gzcgwsp.jzfqwczz.common.web.form.YwYnBusinfoHfqkForm;
import com.augurit.gzcgwsp.jzfqwczz.common.web.form.YwYnBusinfoNssyForm;
import com.augurit.gzcgwsp.ljzyz.entity.YwYnBusinfo;
import com.augurit.gzcgwsp.ljzyz.web.form.YwYnBusinfoForm;

public class YwYnBusinfoConvertor {
	public static YwYnBusinfoForm convertVoToForm(YwYnBusinfo entity) {
		if(entity != null) {
			YwYnBusinfoForm form = new DozerBeanMapper().map(entity, YwYnBusinfoForm.class);
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(YwYnBusinfoForm form, YwYnBusinfo entity) {
		if (form == null) return;
        if (entity == null) entity = new YwYnBusinfo();
        
        new DozerBeanMapper().map(form, entity);
	}
	
	public static List<YwYnBusinfoForm> convertVoListToFormList(List<YwYnBusinfo> ywYnBusinfoList) {
		if(ywYnBusinfoList != null && ywYnBusinfoList.size() > 0) {
			List<YwYnBusinfoForm> ywYnBusinfoFormList = new ArrayList();
			for(int i=0; i<ywYnBusinfoList.size(); i++) {
				ywYnBusinfoFormList.add(convertVoToForm(ywYnBusinfoList.get(i)));
			}
			return ywYnBusinfoFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<YwYnBusinfo> ywYnBusinfoList) {
		if(ywYnBusinfoList != null && ywYnBusinfoList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<ywYnBusinfoList.size(); i++) {
				YwYnBusinfo entity = ywYnBusinfoList.get(i);
				Map<String, String> map = new HashMap();

				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("gsmc", entity.getGsmc());
				map.put("cjh", entity.getCjh());
				map.put("cphm", entity.getCphm());
				map.put("zyzh", entity.getZyzh());
				map.put("zyzyxq", DateUtils.dateTimeToString(entity.getZyzyxq(), "yyyy-MM-dd"));
				map.put("cx", entity.getCx());
				map.put("ccrq", DateUtils.dateTimeToString(entity.getCcrq(), "yyyy-MM-dd"));
				map.put("djrq", DateUtils.dateTimeToString(entity.getDjrq(), "yyyy-MM-dd"));
				map.put("xszyxrq", DateUtils.dateTimeToString(entity.getXszyxrq(), "yyyy-MM-dd"));
				map.put("shrq", DateUtils.dateTimeToString(entity.getShrq(), "yyyy-MM-dd"));
				map.put("shyxq", DateUtils.dateTimeToString(entity.getShyxq(), "yyyy-MM-dd"));
				map.put("fdjh", entity.getFdjh());
				map.put("zzl", entity.getZzl());
				map.put("gpsno", entity.getGpsno());
				map.put("remark", entity.getRemark());
				map.put("shjg", entity.getShjg());
				map.put("ajid", entity.getAjid() == null ? "" : entity.getAjid().toString());
				map.put("qyid", entity.getQyid() == null ? "" : entity.getQyid().toString());
				map.put("spsx", entity.getSpsx());
				map.put("bfyy", entity.getBfyy());
				map.put("shr", entity.getShr());
				//map.put("cczh", entity.getCczh());
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<YwYnBusinfo> convertFormListToVoList(List<YwYnBusinfoForm> ywYnBusinfoFormList) {
		if(ywYnBusinfoFormList != null && ywYnBusinfoFormList.size() > 0) {
			List<YwYnBusinfo> ywYnBusinfoList = new ArrayList();
			for(int i=0; i<ywYnBusinfoFormList.size(); i++) {
				YwYnBusinfo ywYnBusinfo = new YwYnBusinfo();
				convertFormToVo(ywYnBusinfoFormList.get(i), ywYnBusinfo);
				ywYnBusinfoList.add(ywYnBusinfo);
			}
			return ywYnBusinfoList;
		}
		return null;
	}
	
	public static void convertNssyFormToForm(YwYnBusinfoNssyForm ywYnBusinfoNssyForm, YwYnBusinfoForm form) {
        if (ywYnBusinfoNssyForm == null) return;
        if (form == null) form = new YwYnBusinfoForm();        
        new DozerBeanMapper().map(ywYnBusinfoNssyForm, form);
    }
	
	public static void convertHfqkFormToForm(YwYnBusinfoHfqkForm ywYnBusinfoHfqkForm, YwYnBusinfoForm form) {
        if (ywYnBusinfoHfqkForm == null) return;
        if (form == null) form = new YwYnBusinfoForm();        
        new DozerBeanMapper().map(ywYnBusinfoHfqkForm, form);
        if(ywYnBusinfoHfqkForm.getId()!=null){
        	form.setHfqkId(ywYnBusinfoHfqkForm.getId());
        }
        
    }
}